package org.example03.mapper;

import org.apache.ibatis.annotations.*;
import org.example03.po.Product;

public interface ProductMapper {
    @SelectKey(keyProperty = "id", keyColumn = "id", resultType = int.class,
            statement = "SELECT LAST_INSERT_ID() ", before = false)
    @Insert("INSERT INTO mybatis02.product(name, price, detail, pic, createtime) " +
            "VALUES(#{name},#{price}, #{detail},#{pic} ,#{createTime} )")
    void insertProduct(Product product);
    @Results({
            @Result(column = "pid", property = "id",id = true),
            @Result(column = "name", property = "name"),
            @Result(column = "price", property = "price"),
            @Result(column = "detail", property = "detail"),
            @Result(column = "pic", property = "pic"),
            @Result(column = "createtime", property = "createTime")
    })
    @Select("SELECT id AS pid FROM mybatis02.product WHERE id = #{id}")
    Product getProductById(int id);
}

